package com.simple.trade.controller.india;

import com.simple.common.entity.ResData;
import com.simple.common.entity.controller.BaseController;
import com.simple.common.entity.req.india.req.V3Req;
import com.simple.common.entity.req.india.res.V3Res;
import com.simple.common.entity.req.vm.pay.QueryTradeReq;
import com.simple.common.entity.vo.pay.IndiaQueryTradeRes;
import com.simple.common.entity.vo.pay.QueryTradeRes;
import com.simple.trade.holder.PayContext;
import com.simple.trade.service.india.IndiaQueryTradeService;
import com.simple.trade.service.india.V3PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import static com.simple.common.entity.constant.Payment.INDIA_PAY_CODE;


/**
 * @author kang
 * @date 2021年11月02日 15:41
 * @description
 */
@RestController
public class IndiaPayController extends BaseController {

    @Autowired
    V3PayService v3PayService;

    @Autowired
    IndiaQueryTradeService indiaQueryTradeService;

    /**
     * 支付下单
     * @param req
     * @return
     */
    @PostMapping("/v3/cashier")
    public ResData<V3Res> cashierPay(@RequestBody @Validated V3Req req) {
        PayContext.current().iam(req.getAppId(), INDIA_PAY_CODE);
        req.check();
        return v3PayService.cashierPay(req);
    }

    /**
     * 查询支付
     * @param req
     * @return
     */
    @PostMapping("/v3/query")
    public ResData<IndiaQueryTradeRes> queryTrade(@RequestBody @Validated QueryTradeReq req) {
        req.check();
        ResData<IndiaQueryTradeRes> queryTradeResResData = indiaQueryTradeService.queryTrade(req);
        return queryTradeResResData;
    }
}
